﻿<%--
 *  File:    VisitPlanEditDetail.jsp
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  String strModuleName = "SFE";
  String privilegeCode = "H0255,H0256,H0259";
  	String contextPath = request.getContextPath();
%>



<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title></title>
<%
if("Y".equals(request.getParameter("isconfirm"))){%>

%>
<script>
	parent.opener.refreshWindow();
</script>
<%return;
}%>	
<%
int nYear=0;
int nMonth=0;
int nWeek=0;
if(request.getParameter("year")!=null)
{
	nYear=Integer.parseInt(request.getParameter("year"));
}
else if(session.getAttribute("year")!=null)
{
	nYear=((Integer)session.getAttribute("year")).intValue();
}
if(request.getParameter("monthofyear")!=null)
{
	nMonth=Integer.parseInt(request.getParameter("monthofyear"));
}
else if(session.getAttribute("monthofyear")!=null)
{
	nMonth=((Integer)session.getAttribute("monthofyear")).intValue();
}
if(request.getParameter("weekofmonth")!=null)
{
	nWeek=Integer.parseInt(request.getParameter("weekofmonth"));
}
else if(session.getAttribute("weekofmonth")!=null)
{
	nWeek=((Integer)session.getAttribute("weekofmonth")).intValue();
}
Date dWeekStart=null;
Date dWeekEnd=null;
String strWeekStart="";
String strWeekEnd="";
String strFullDateFormat=label.getLabelName("L_FullDateFormat");
int nStartDayWeekOfMonth=0;
Calendar cal=null;
if(nYear>0 && nMonth>0 && nWeek>0)
{
	cal=Calendar.getInstance();
	cal.clear();
	cal.set(Calendar.YEAR, nYear);
	cal.set(Calendar.MONTH, nMonth-1);
	cal.set(Calendar.WEEK_OF_MONTH, nWeek);
	cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
	dWeekEnd=cal.getTime();
	
	cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
	dWeekStart=cal.getTime();
	nStartDayWeekOfMonth=cal.get(Calendar.WEEK_OF_MONTH);
	session.setAttribute("weekstart",new java.sql.Date(dWeekStart.getTime()));
	session.setAttribute("weekend",new java.sql.Date(dWeekEnd.getTime()));
	
	java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(strFullDateFormat);
	strWeekEnd=sdf.format(dWeekEnd);
	strWeekStart=sdf.format(dWeekStart);
	
}
%>
<PageFlow:CheckPageFlow pageName="p_visitplantempletselectdetail"/>
<%@ include file="/inc/InitEdit.inc" %>
<%

 pageContext.setAttribute("year",new Integer(cal.get(Calendar.YEAR)));
 pageContext.setAttribute("monthofyear",new Integer(cal.get(Calendar.MONTH)+1));
 pageContext.setAttribute("weekofmonth",new Integer(cal.get(Calendar.WEEK_OF_MONTH)));
 
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script>
	parent.document.title="<%=label.getLabelName("L_AddFromTemplet")%>";
function page_confirm()
{
	if(!page_save())
		return;
	parent.opener.refreshWindow();
}

function page_cancel()
{
	parent.close();
}


function page_save()
{
	var myform = eval("document.cform");
	if(Number(myform.numrows.value)<1)
	 return true;
	 	var details=eval("myform.customerids");
	if(isNullChecked(details))
	  {
	    alert("<%= message.getMessageDesc("MUST_SELECT_ONE_RECORD") %>");
	    return false;
	  } 
	for(i=0;i<Number(myform.numrows.value);i++)
	{
		var sstart=eval("myform.splanstarttime"+i);
		var send=eval("myform.splanendtime"+i);
		var tsstart=eval("myform.tsplanstarttime"+i);
		var tsend=eval("myform.tsplanendtime"+i);
		
		var dvisit=eval("myform.planvisitdate"+i);
		var checkboxobj=eval("myform.checkboxobj"+i);
		var chkids=eval("myform."+checkboxobj.value);
		var hiddenCustomerID=eval("myform.hiddenCustomerID"+i);
		var customerid=eval("myform.customerid"+i);
	  if(chkids.checked)
	  {
			<%--		
		if(isEmpty(tsstart.value))
			{
				alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitPlanStartTime"))%>");
				return false;
			}
			if(isEmpty(tsend.value))
			{
				alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitPlanEndTime"))%>");
				return false;
			}
			if(!isTime(tsstart.value,"HH:mm"))
			{
				alert("<%=message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_VisitPlanStartTime"))%>(HH:mm)");
				return false;
			
			}
			if(!isTime(tsend.value,"HH:mm"))
			{
				alert("<%=message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_VisitPlanEndTime"))%>(HH:mm)");
				return false;
			
			}--%>
		sstart.value=dvisit.value+" "+"01:00:00";
		send.value=dvisit.value+" "+"01:00:00";
			
		customerid.value=hiddenCustomerID.value;
	}
	else
		{
			customerid.value=" ";
		}
	}
		myform.actionname.value = "save";
 		myform.target="_self";
 		isRunning = true;
 		myform.submit();
 		return false;
}

</script>	
</head>

<body>
	<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_visitplantempletselectdetail">
    <input type="hidden" name="actionname">
    <custom:hidden property="contactid"/>
    <custom:hidden property="orgid"/>
    <custom:hidden property="year"/>
    <custom:hidden property="monthofyear"/>
    <custom:hidden property="weekofmonth"/>
    <custom:hidden property="ishistory"/>	
    <custom:hidden property="weekstart"/>
    <custom:hidden property="weekend" />	
    <custom:hidden property="visitplantempletid"/>	
    	 <input type="hidden" name="removedempty" value=" "/>	
    <table width="100%" cellspacing="0" border="0" cellpadding="0">
    	<tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
             <tr class="deepblue-left"> 
             		<td class="title_center" width="22" rowspan="2" >&nbsp;</td>
          			<td class="title_center" width="60" rowspan="2" ><%=label.getLabelName("L_Week")%></td>
          			<td class="title_center"  colspan="7" ><%=label.getLabelName("L_VisitCustomList")%></td>
          	</tr>
          	<tr class="deepblue-left">
          			<td class="title_center"  width="60" ><%=label.getLabelName("L_CustomerCode")%></td>
          		  <td class="title_center"   ><%=label.getLabelName("L_CustomerName")%></td>
          		  <td class="title_center"  width="60" ><%=label.getLabelName("L_OrgPCName")%></td>
          		  <td class="title_center"  width="80" ><%=label.getLabelName("L_ProcessName")%></td>
          	<!--   <td class="title_center"  width="60" ><%=label.getLabelName("L_VisitPlanStartTime")%></td>
          		  <td class="title_center"  width="60" ><%=label.getLabelName("L_VisitPlanEndTime")%></td> -->	
          		  <td class="title_center" width="50"><%=label.getLabelName("L_NeedAssist")%></td>
          	</tr>	
          	<%
          	String[] weekLabelArrs=new String[]{"L_Sunday","L_Monday","L_Tuesday","L_Wednesday","L_Thursday","L_Friday","L_Saturday"};
		
          	Vector vDetails=(Vector)pageContext.getAttribute("visitplantempletdetails");
          	if(vDetails==null)
          		vDetails=new Vector();
          	int currRec=0;
          		int currDay=0;
          		int numCount=0;	
          	if(	vDetails.size()>0)
          	{
          		 currRec=0;
          		 currDay=0;
          		 numCount=0;
          		HashMap oneDetail=(HashMap)vDetails.get(currRec);
          		java.text.SimpleDateFormat  visitSdf=new java.text.SimpleDateFormat("yyyy-MM-dd");
	          	while(oneDetail!=null)
	          	{
	          	pageContext.setAttribute("templetdetailinfo",oneDetail);
	          	Integer oCurrRec=new Integer(currRec);
	          		if(currDay!=((Integer)oneDetail.get("datetype")).intValue())
	          		{
	          			if(currDay!=0)
	          			{
	          			%>
	          			<script>
	          				td_chk_<%=currDay%>.rowSpan=<%=numCount%>;
	          				td_dayofweek_<%=currDay%>.rowSpan=<%=numCount%>;
	          			</script>	
	          			<%
	          			numCount=0;
	          			}
	          			currDay=((Integer)oneDetail.get("datetype")).intValue();
	          			
	          			%>
	          				<tr >
	          						<td  rowspan="1" id="td_chk_<%=currDay%>"><input type="checkbox" name="customerids" id="chkids<%=currDay%>" value="" class="normalradio"/></td>
	 					  		
	          						<td rowspan="1" id="td_dayofweek_<%=currDay%>"><%=label.getLabelName(weekLabelArrs[currDay-1])%></td>
	          			<%
	          			
	          		}
	          		else
	          		{
	          		%>
	          			<tr >
	          		<%}
	          		Calendar calPlan=Calendar.getInstance();
	          		calPlan.clear();
	          		calPlan.setTime(cal.getTime());
	          		
	          		calPlan.add(Calendar.DATE,currDay-1);
	          		
	          		%>		  			
	          						<td>
	          							<custom:hidden name="templetdetailinfo" property="customerid" changedName="hiddenCustomerID" colIndex="<%=oCurrRec%>"/>
	          							<custom:hidden name="templetdetailinfo" property="customerid"  colIndex="<%=oCurrRec%>"/>
	          							<input type="hidden" name="planvisitdate<%=currRec%>" value="<%=visitSdf.format(calPlan.getTime())%>"	/>
	          							<input type="hidden" name="dayofweek<%=currRec%>" value="<%=calPlan.get(Calendar.DAY_OF_WEEK)%>"	/>
	          							<input type="hidden" name="year<%=currRec%>" value="<%=calPlan.get(Calendar.YEAR)%>"	/>
	          							<input type="hidden" name="monthofyear<%=currRec%>" value="<%=calPlan.get(Calendar.MONTH)+1%>"	/>
	          							<input type="hidden" name="weekofmonth<%=currRec%>" value="<%=calPlan.get(Calendar.WEEK_OF_MONTH)%>"	/>
	          							
	          							<custom:write name="templetdetailinfo" property="customercode" nbsp="true"/>
	          							<input type="hidden" name="splanstarttime<%=currRec%>" />		
													<input type="hidden" name="splanendtime<%=currRec%>" />	
													<input type="hidden" name="checkboxobj<%=currRec%>" value="chkids<%=currDay%>" />	
																	
				
												</td>	
	          						<td><custom:write name="templetdetailinfo" property="customername"  nbsp="true"/></td>
	          						<td><custom:write name="templetdetailinfo" property="globalpcname"  nbsp="true"/></td>
	          						<td><custom:select  name="templetdetailinfo"	 property="processid"  optionsName="allprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"  colIndex="<%=oCurrRec%>" /></td>
	          						<!--  <td><input type="text" size="6" name="tsplanstarttime<%=currRec%>"  /></td>
												<td><input type="text" size="6" name="tsplanendtime<%=currRec%>"   /></td> -->
												<td><input type="checkbox"  name="needassist<%=currRec%>" value="Y"  class="normalradio" ></td>
									  </tr>
	          			
	          			
	          		<%
	          		currRec++;
	          		numCount++;
	          		if(currRec>=vDetails.size())
	          			break;
	          		oneDetail=(HashMap)vDetails.get(currRec);
	          		}
	          		if(currDay!=0)
	          		{%>
	          		
	          		<script>
	          				td_chk_<%=currDay%>.rowSpan=<%=numCount%>;
	          				td_dayofweek_<%=currDay%>.rowSpan=<%=numCount%>;
	          			</script>	
	          			<%
	          	}
	          	
	          	%>
          	
					<%}%>	
				</table>
				<input type="hidden" name="numrows" value="<%=currRec%>"/>
			</td>
		</tr>
		<tr>
      	<td>
      		<table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
             <a onclick="page_confirm();"><custom:button type="1" label="L_Confirm" imgsrc="new.gif" border="0" style="width:60"/></a>
                
                <a onclick="page_cancel();"><custom:button type="1" label="L_Cancel" imgsrc="Modify.gif" border="0" style="width:60"/></a>
                
               
              </td>
            </tr>
          </table>  
        </td>
      </tr>
	</table>				
</body>

</html>
	
